package DataBaseTest;

import java.awt.EventQueue;

import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Color;
import java.awt.Font;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.awt.SystemColor;

public class Insert extends JInternalFrame {
	
	Connection conn;
	DataBaseTest_0528 main;
	private JLabel lblNewLabel;
	private JLabel lblNewLabel_1;
	private JTextField code;
	private JTextField ea;
	private JButton btnNewButton;
	private JLabel lblNewLabel_2;

	/**
	 * Launch the application.
	 */

	/**
	 * Create the frame.
	 */
	public Insert(Connection c,DataBaseTest_0528 main) {
;
		getContentPane().setBackground(SystemColor.window);
		this.conn=c;
		this.main=main;
		setMaximizable(true);
		setClosable(true);
		setTitle("입력");
		setBounds(100, 100, 232, 253);
		getContentPane().setLayout(null);
		getContentPane().add(getLblNewLabel());
		getContentPane().add(getLblNewLabel_1());
		getContentPane().add(getCode());
		getContentPane().add(getEa());
		getContentPane().add(getBtnNewButton());
		getContentPane().add(getLblNewLabel_2());

	}
	private JLabel getLblNewLabel() {
		if (lblNewLabel == null) {
			lblNewLabel = new JLabel("코드 ");
			lblNewLabel.setBackground(SystemColor.inactiveCaption);
			lblNewLabel.setFont(new Font("서울남산체 L", Font.PLAIN, 13));
			lblNewLabel.setForeground(SystemColor.desktop);
			lblNewLabel.setBounds(12, 21, 57, 15);
		}
		return lblNewLabel;
	}
	private JLabel getLblNewLabel_1() {
		if (lblNewLabel_1 == null) {
			lblNewLabel_1 = new JLabel("EA");
			lblNewLabel_1.setBackground(SystemColor.inactiveCaption);
			lblNewLabel_1.setFont(new Font("서울남산체 L", Font.PLAIN, 13));
			lblNewLabel_1.setForeground(SystemColor.desktop);
			lblNewLabel_1.setBounds(12, 61, 57, 15);
		}
		return lblNewLabel_1;
	}
	private JTextField getCode() {
		if (code == null) {
			code = new JTextField();
			code.setBounds(85, 18, 116, 21);
			code.setColumns(10);
		}
		return code;
	}
	private JTextField getEa() {
		if (ea == null) {
			ea = new JTextField();
			ea.setBounds(85, 58, 116, 21);
			ea.setColumns(10);
		}
		return ea;
	}
	private JButton getBtnNewButton() {
		if (btnNewButton == null) {
			btnNewButton = new JButton("저 장");
			btnNewButton.setFont(new Font("서울남산체 L", Font.PLAIN, 13));
			btnNewButton.setForeground(SystemColor.desktop);
			btnNewButton.setBackground(SystemColor.window);
			btnNewButton.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
				try {
					String c= code.getText();
					int ee= Integer.parseInt(ea.getText());
					
					String sql="Insert into ptbl(serial,code,ea) values(ptbl_serial.nextval,?,?)";
					PreparedStatement pstmt=conn.prepareStatement(sql);
					pstmt.setString(1, c);//1은 첫번쨰 물음표 
					pstmt.setInt(2, ee);
					
					pstmt.executeUpdate();//입력,수정,삭제
					
					//if(main.select !=null)main.select.setList();
				} catch (Exception e2) {
					e2.printStackTrace();
					}
				}
			});
			btnNewButton.setBounds(85, 107, 116, 23);
		}
		return btnNewButton;
	}
	private JLabel getLblNewLabel_2() {
		if (lblNewLabel_2 == null) {
			lblNewLabel_2 = new JLabel("데이터를 입력해주세요");
			lblNewLabel_2.setBackground(SystemColor.inactiveCaption);
			lblNewLabel_2.setFont(new Font("서울남산체 L", Font.PLAIN, 13));
			lblNewLabel_2.setForeground(SystemColor.desktop);
			lblNewLabel_2.setBounds(12, 164, 322, 15);
		}
		return lblNewLabel_2;
	}
}
